package Beans;

import BO.*;
import UI.*;
import java.io.Serializable;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public class ProfileBean implements Serializable{

    private List<StatusUI> updates;
    private List<UserUI> friends;
    
    public ProfileBean() {
    }

    public List<StatusUI> getUpdates() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UserUI user = (UserUI)session.getAttribute("User");
        if(user != null){
            updates = Service.getFriendStatusUpdates(user.getId());
        }
        return updates;
    }

    public void setUpdates(List<StatusUI> updates) {
        this.updates = updates;
    }

    public List<UserUI> getFriends() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UserUI user = (UserUI)session.getAttribute("User");
        
        if(user != null){
            friends = Service.getUserFriends(user.getId());
        }
        return friends;
    }

    public void setFriends(List<UserUI> friends) {
        this.friends = friends;
    }
    
    public void removeFriendListener(ActionEvent event){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UserUI user = (UserUI)session.getAttribute("User");
        Service.removeFriendship(user.getId(),((UserUI) event.getComponent().getAttributes().get("selection")).getId());

    }

}
